/*
 * $Id$
 */

package py.windmill.util;

import java.io.InputStream;
import java.util.Properties;

/**
 *
 * @author py
 */
public class PropertiesDatabaseFactory {

    private Properties _prop = new Properties();

    public PropertiesDatabaseFactory(final String fn) {
        try {
            final InputStream input = 
                    PropertiesDatabaseFactory.class.getResourceAsStream(fn);
            try {
                _prop.load(input);
            }
            finally {
                if (null != input) {
                    input.close();
                }
            }
        }
        catch (final Exception ex) {
            throw new RuntimeException(ex);
        }
    }

    public Database newDatabase() {
        return Database.mysql().setHost(_prop.getProperty("jdbc.host"))
                .setPort(Integer.parseInt(_prop.getProperty("jdbc.port")))
                .setName(_prop.getProperty("jdbc.name"))
                .setUsername(_prop.getProperty("jdbc.username"))
                .setPassword(_prop.getProperty("jdbc.password"));
    }
    
}
